

<template>
<div>
     <!-- <Button type="primary" @click="modal1 = true">Display dialog box</Button> -->
     <Modal v-model="mode" width="45%"  title="公司信息修改" @change="testChange"  @on-cancel="cancel">
         <Row>
          <Form ref="CompanyData"  :model="CompanyData"  :rules="ruleInUser" :label-width="100">
                <div style="width:90%;height:auto;margin:0 auto;">
                     <Col span="24">
                       <FormItem label="公司编号：" prop="Id">
                          <Input v-model="CompanyData.Id" class="orders_disabled" placeholder="请输入用户编号" disabled />
                       </FormItem>
                     </Col>
                    <Col span="12"> 
                      <FormItem label="公司名称：" prop="CompanyName">
                        <Input v-model="CompanyData.CompanyName"  placeholder="请输入公司名称"/>
                      </FormItem> 
                      
                     <FormItem label="公司联系人：" prop="CompanyLinkman">
                        <label slot="label">联系人：</label>
                        <Input v-model="CompanyData.CompanyLinkman" placeholder="请输入公司联系人"/>
                     </FormItem> 
                      <FormItem label="公司电话：" prop="CompanyTelephone">
                          <label slot="label">公司电话：</label>
                          <Input v-model="CompanyData.CompanyTelephone" placeholder="请输入公司电话"/>
                      </FormItem> 
                      <FormItem label="公司地址：" prop="CompanyAddr">
                          <label slot="label">公司地址：</label>
                          <Input v-model="CompanyData.CompanyAddr" placeholder="请输入公司地址信息"/>
                      </FormItem> 
                      
                                                
                    </Col>


                    <Col span="24">
                        <FormItem label="备注：" prop="Remark">
                            <label slot="label">备&nbsp;&nbsp;&nbsp;&nbsp;注：</label>
                            <Input v-model="CompanyData.CompanyRemark" style="width:500px;" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请说明备注事项..."/>
                         </FormItem>
                    </Col>
                    
                    <Col span="24">
                        <FormItem>
                            <Button type="primary" :loading="loading"  @click="handleSubmit('CompanyData')">提交</Button>
                            <!-- <Button @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button> -->
                         </FormItem>
                   </Col>
                   
                </div>
              </Form>
        </Row>


        <div slot="footer" >
            <!-- <Button type="error" size="large" long :loading="modal_loading" @click="del">Delete</Button> -->
        </div>
    </Modal>
</div>
</template>

<script>
import {getCompanyList,getDeptList,updateUserData,getUserlist,getVehlist,subOrderData} from "@/api/data";
import { formatDate } from '../../components/date.js';
export default {
    name: 'Edit',
    data () {
        return {
          loading:false,
          mode:this.edit,
          
          //表单验证规则
          ruleInUser: {
            CompanyName: [
              { required: true, message: '请填写公司名称', trigger: 'blur' }
            ],

            CompanyLinkman: [
              { required: true, message: '请填写公司联系人', trigger: 'blur' }
            ],

            CompanyTelephone: [
              { required: true, message: '请填写公司电话号码', trigger: 'blur' }
            ],
            
            CompanyAddr: [
              { required: true, message: '请填写公司地址', trigger: 'blur' }
            ],


          },
         
          listdata:[]

        };
    },
    props:{
        edit:{
            type:Boolean ,
            required:true
        },
        CompanyData:{
            type:Object,
            required:true 
        },
        


    },
    methods: {
      testChange(val){
        this.$emit('testChange',val);
       },
      cancel(){
           this.loading = false; 
          let data = {
            mode:false
          }
          this.$emit('cancelCallBack', data);
       },
      //提交编辑后的userInfo
      handleSubmit(name) {
        
        this.$refs[name].validate(valid => { 
          console.log("提交验证：",valid)    
          if (valid) {  
            this.loading = true;      
            this.submit();
          } else {
            this.$Message.error("请填写相关信息!");
          }
        });
      },
    submit(){
        const data = {
            Id:this.CompanyData.Id,
            CompanyName: this.CompanyData.CompanyName,
            CompanyLinknam: this.CompanyData.CompanyLinkman,
            CompanyTelephone: this.CompanyData.CompanyTelephone,
            CompanyAddr: this.CompanyData.CompanyAddr,
            CompanyRemark: this.CompanyData.CompanyRemark,
    };
      updateUserData(data).then(res =>{
            if(res == "OK"){
              this.$Message.success("提交成功");
              this.loading = false; 
              let data = {
                mode:false
              }
              this.$emit('success', data);   
            }else if(response.data.flag == 0){
            this.$Message.success("提交失败"); 
            }else if(response.data.flag == 2){
            this.$Message.success("状态过期");
            }
        }).catch(error => {
            this.$Message.error("请核对之后重新提交1");
             this.loading = false; 
       });


     },
    },
    mounted () {
      const cmpdata = {
        fields:"Id,CompanyName",
        offset:"0",
        limit:"-1"
      };
      const dptdata = {
        fields:"Id,DeptName",
        offset:"0",
        limit:"-1"
      };
      //获得包含公司Id和companyname字段的全部列表
      getCompanyList(cmpdata).then(res =>{
        this.CompanyList = res.List;
        
      });
      //获得包含公司Id和companyname字段的全部列表
      getDeptList(dptdata).then(res =>{
        this.DeptList = res.List;
      });
    },
    watch: {
        edit(val) {
        this.mode = val
    }
}
}
</script>
<style>
.dept .ivu-select-placeholder{
color:#515a6e!important;
}
</style>